<?php

namespace App\Admin\Controllers\User;

use App\Models\Cms\QuestionCategory;
use App\Models\User\User;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;

class UserController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(User::with(['wechatMiniUser', 'avatarFile', 'familyUsers']), function (Grid $grid) {
            $grid->disableCreateButton();
            $grid->disableEditButton();
//            $grid->showQuickEditButton('编辑');
//            $grid->setDialogFormDimensions('80%', '90%');

            $grid->model()->orderBy('created_at', 'desc');

            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('phone');
            $grid->column('sex')->using(['未知', '男', '女']);
            $grid->column('avatarFile.url')->image('', 50, 50);
            $grid->column('is_verifier')->switch();
            $grid->column('address');
            $grid->column('status')->using(trans('user.options.status'));
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->expand();

                $filter->like('name')->width('300px');
                $filter->like('phone')->width('300px');
                $filter->equal('status')->select(trans('user.options.status'))->width('300px');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new User(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('phone');
            $show->field('sex');
            $show->field('avatar');
            $show->field('is_verifier');
            $show->field('address');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new User(), function (Form $form) {
            $form->text('name');
            $form->text('phone');
            $form->select('sex')->options(['未知', '男', '女']);
            $form->uploadimagepro('avatar');
            $form->switch('is_verifier');
            $form->text('address');
            $form->text('status');
        });
    }
}
